<?php
class Con_cache extends Acan{
	
	public $defaultAct='eaccelerator';
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
	}
	function Act_memcache(){
		$this->atitle = 'Memcache';
		global $Amem;
		if($_POST){
			$Amem->flush();
		}
		$stats = $Amem->getStats();
		$day = floor($stats[uptime]/86400);
		$hour = floor(fmod($stats[uptime],86400)/3600);
		$minute = floor(fmod(fmod($stats[uptime],86400),3600)/60);
		$second = fmod(fmod(fmod($stats[uptime],86400),3600),60);
		include $this->atpl();
	}
	function Act_eaccelerator(){
		if (!function_exists('eaccelerator_info')) {
			die('你的服务器没有eAccelerator扩展，不能支持此功能，请安装后再操作！');
		}
		if (isset($_POST['cachingoff'])) eaccelerator_caching(false);
		if (isset($_POST['cachingon'])) eaccelerator_caching(true);
		if (isset($_POST['optoff']) && function_exists('eaccelerator_optimizer')) eaccelerator_optimizer(false);
		if (isset($_POST['opton']) && function_exists('eaccelerator_optimizer')) eaccelerator_optimizer(true);
		if (isset($_POST['mtimeoff'])){eaccelerator_check_mtime(false);}
		if (isset($_POST['mtimeon'])) eaccelerator_check_mtime(true);
		if (isset($_POST['clear'])) eaccelerator_clear();
		if (isset($_POST['clean'])) eaccelerator_clean();
		if (isset($_POST['purge'])) eaccelerator_purge();


		$info = eaccelerator_info();
		if($info[cache]==1){
			$infos['cache'] = '<font color=green>开启</font>';
			$infon['cache'] = 'cachingoff';
			$button['cache'] = '关闭';
		}else{
			$infos['cache'] = '<font color=red>关闭</font>';
			$infon['cache'] = 'cachingon';
			$button['cache'] = '开启';
		}
		if($info[optimizer]==1){
			$infos['optimizer'] = '<font color=green>开启</font>';
			$infon['optimizer'] = 'optoff';
			$button['optimizer'] = '关闭';
		}else{
			$infos['optimizer'] = '<font color=red>关闭</font>';
			$infon['optimizer'] = 'opton';
			$button['optimizer'] = '开启';
		}
		if($info[check_mtime]==1){
			$infos['check_mtime'] = '<font color=green>开启</font>';
			$infon['check_mtime'] = 'mtimeoff';
			$button['check_mtime'] = '关闭';
		}else{
			$infos['check_mtime'] = '<font color=red>关闭</font>';
			$infon['check_mtime'] = 'mtimeon';
			$button['check_mtime'] = '开启';
		}
		//-----------------------------------------------------------------------
		$info['rate'] = round($info['memoryAllocated']*100/$info['memorySize'],2).'%';
		$info['memorySize'] = Afun_format_size($info['memorySize']);
		$info['memoryAvailable'] = Afun_format_size($info['memoryAvailable']);
		$info['memoryAllocated'] = Afun_format_size($info['memoryAllocated']);
			$scripts = eaccelerator_cached_scripts();
		//--分页函数
			//脚本
			$akey = str_replace('\\\\','\\',Afun_request('akey'));
			if($akey){$page->other = '?akey='.$akey;}
			$page->theurl = $this->Aactr.'-'.$this->id;
		//	$page->theurl = "cache-eaccelerator-";
			$page->page = '20';
			$page->by = 'mtime';
			//--搜索数组
			unset($i,$val);
			$akeys = Afun_replace_val($akey);
			foreach($scripts as $i=>$val){
				if(preg_match ("/$akeys/i",$val['file'])) {
					$total['size'] += $val['size'];
					$listks[] = $val;
				}
			}
			$page->counts = count($listks);	//统计总数目
			$pages = Afun_apage($page);
			$apage= $pages->html;
			//--排序数组
			$listks = Afun_arr_sort($listks,$pages->by,$pages->order);
			$irr[0] = $pages->start;
			$irr[1] = $pages->page;
			//分页结束
			//--分页数组
			if(is_array($listks)){
				unset($i,$val);
				foreach($listks as $i=>$val){
					$val['id'] = $i+1;
					if($i>=(($irr[0]-1)*$irr[1]) && $i<($irr[0]*$irr[1])){
						$val['size'] = Afun_format_size($val['size']);
						$val['mtime'] = date('Y-m-d H:i:s',$val['mtime']);
						$lists[] = $val;
					}
				}
			}
			$total['size'] = Afun_format_size($total['size']);
		//	$removed = eaccelerator_removed_scripts();
		//-----------------------------------------------------------------------
	/*返回用于替换的字符串*/
		include $this->atpl();
	}
	//keys
	function eaccelerator_keys(){
		if (!function_exists('eaccelerator_info')) {
			die('eAccelerator isn\'t installed or isn\'t compiled with info support!');
		}
			$keysls = eaccelerator_list_keys();
		//--分页函数
			$akey = Afun_request('akey');
			if($akey){
				$a_other = '/akey/'.$akey;
			}
			$a_theurl = "/admin.php?a=setting/eaccelerator_keys/*";
			$arr['page'] = '30';


			if(empty($age['apage']))
				$age['apage'] = '1';
			$irr = explode('-',$age['apage']);
			if(empty($irr[1]))
				$irr[1] = $arr['page'];
			if($age['aorder']){
				$orr = explode('-',$age['aorder']);
				$order = $orr[0];
				$by = $orr[1];
			}
			if(empty($order)){
				$order = 'created';
			}
			if(empty($by))
				$by = 'DESC';
			//--排序数组
			$keysls = Afun_arr_sort($keysls,$order,$by);
			if($by == 'ASC'){
				$by = 'DESC';
			}else{
				$by = 'ASC';
			}
			//--搜索数组
			unset($i,$val);
			$akeys = Afun_replace_val($akey);
			foreach($keysls as $i=>$val){
				if(preg_match ("/$akeys/i",$val['name'])) {
					$total['size'] += $val['size'];
					$listks[] = $val;
				}
			}
			//--分页数组
			if(is_array($listks)){
				unset($i,$val);
				foreach($listks as $i=>$val){
					$val['id'] = $i+1;
					if($i>=(($irr[0]-1)*$irr[1]) && $i<($irr[0]*$irr[1])){
						$nrr = explode(':',$val['name']);
						$val['name'] = $nrr[1];
						$val['size'] = Afun_format_size($val['size']);
						$val['created'] = date('Y-m-d H:i:s',$val['created']);
						if($val['ttl']=='0'){
							$val['ttl'] = '永久';
						}elseif($val['ttl']=='-1'){
							$val['ttl'] = '过期';
						}elseif($val['ttl']>0){
							$val['ttl'] = date('Y-m-d H:i:s',$val['ttl']);
						}
						$lists[] = $val;
					}
				}
			}
			$total['size'] = Afun_format_size($total['size']);
			$a_counts = count($listks);	//统计总数目
			$acanpages = Afun_pages($a_counts,$age['apage'],$a_theurl,$age['aorder'],$a_other,$arr);
			$apage= $acanpages['html'];

		//操作
			if($age['ac']=='show'){//显示keys
				$namerrs = unserialize(eAccelerator_get($age['name']));
			}elseif($age['ac']=='del'){//删除keys
				eAccelerator_rm($age['name']);
				Afun_refresh('删除成功',$a_theurl);
			}
		//-----------------------------------------------------------------------
		include_once $this->Atpl();
	}
}

?>